<?
function flash_message($type, $text)
{
	$ci =& get_instance();
	$ci->session->set_flashdata('message', $text);
	$ci->session->set_flashdata('message_type', $type);
}

function permission($type, $permission, $redirect = TRUE)
{
	$ci =& get_instance();
	
	if( ! $ci->ion_auth->logged_in() )
		cms_redirect('auth/login');

	$allow = FALSE;
	if($ci->config->item($type . '_' . $permission) == 1)
		$allow = TRUE;
	
	if($allow == FALSE)	
		if($redirect)
		{
			show_error(group('name') . 'You do not have permission for : ' . $type . '_' . $permission . ' = ' . $ci->config->item($type . '_' . $permission) . '<br />' . print_r($ci->ion_auth->user()->row_array(), true), 403, 'Sorry');
			die();
		}
			
	return $allow;
}

function cms_redirect($path)
{
	redirect(config_item('cms_uri') . '/' . $path);
}

function cms_url($path)
{
	return site_url(config_item('cms_uri') . '/' . $path);	
}

function user($data)
{
	$ci =& get_instance();
	
	if( ! $ci->ion_auth->logged_in() )
		return '';
	
	$user = $ci->config->item('user');
	return $user[$data];
}

function group($data)
{
	$ci =& get_instance();
	
	if( ! $ci->ion_auth->logged_in() )
		return '';
	
	$group = $ci->config->item('group');
	print_r($group);
	return $group[$data];
}